#定义工具链
TOOLCHAIN = arm-none-eabi-
#定义编译器
CC        = $(TOOLCHAIN)gcc
AS        = $(TOOLCHAIN)as
LD        = $(TOOLCHAIN)ld
OBJCOPY   = $(TOOLCHAIN)objcopy
OBJDUMP   = $(TOOLCHAIN)objdump
#定义编译标志
CCFLAGS   = -Wall -mcpu=cortex-m3 -mthumb -nostartfiles -T boot.ld
ASFLAGS   = -mcpu=cortex-m3 -mthumb
LDFLAGS   = -T boot.ld
CPFLAGS   = -Obinary
DUFLAGS   = -S -D
DEBUG	  = -g
#生成的目标
TARGET    = boot.bin
OBJ       = boot.o SystemInit.o main.o led.o
#目标生成规则
all:$(TARGET)
#生成反汇编代码
	$(OBJDUMP) $(DUFLAGS) boot.out > boot.list

$(TARGET):boot.out
#生成二进制代码，格式为bin
	$(OBJCOPY) $(CPFLAGS) boot.out $(TARGET)
	
boot.out:$(OBJ)
#链接目标代码
	$(LD) $(LDFLAGS) -o boot.out $(OBJ)
	
%.o:%.s
#汇编.s文件
	$(CC) $(CCFLAGS) $(DEBUG) -c -o $@ $^ 
	
%.o:%.c
#编译C文件
	$(CC) $(CCFLAGS) $(DEBUG) -c -o $@ $^ 

#伪指令，用于清除文件
.PHONY:clean
clean:
	del *.o *.bin *.out *.list